#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
int mod = 200907;

int qmi(int q, int k){
    int res = 1;
    while(k){
        if(k & 1){
            res = (LL)res * q % mod;
        }

        q = (LL)q * q % mod;
        k >>= 1;
    }
    return res % mod;
}


int main()
{

    int T;
    scanf("%d", &T);
    int a, b, c, k;
    while (T -- )
    {
        scanf("%d%d%d%d", &a, &b, &c, &k);

        if(b - a == c - b){
            int d = b - a;
            int res = (a + (b - a) * (LL)(k - 1)) % mod;
            printf("%d\n", res);
        }
        else{
            int q = b / a;
            int res = (LL) a * qmi(q, k - 1) % mod;
            printf("%d\n", res);
        }
    }

    return 0;
}